package com.exam.api.modules.system.controller.manager;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.system.dto.*;
import com.exam.api.modules.system.vo.BasicUserInfo;
import com.exam.api.modules.system.vo.LoginUserInfo;
import com.exam.api.modules.system.vo.UserVO;
import com.exam.api.modules.system.service.TblUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (管理端) 用户相关接口
 *
 * @author bcheng
 */
@Tag(name = "(管理端) 用户相关接口", description = "(管理端) 用户相关接口")
@RestController
@RequestMapping("/manager/user/")
@SaCheckLogin
@TinyResponse
public class UserManagerController {

    @Resource
    private TblUserService tblUserService;

    @Operation(summary = "用户分页列表", description = "用户分页列表")
    @PostMapping("/page")
    public IPage<UserVO> pageUser(@RequestBody @Validated UserPageDTO dto) {
        return tblUserService.pageUser(dto);
    }

    @Operation(summary = "用户信息", description = "用户信息")
    @PostMapping("/info")
    public LoginUserInfo getUser(@RequestBody @Validated UserIdDTO dto) {
        return tblUserService.getUser(dto);
    }

    @Operation(summary = "更新密码", description = "更新密码")
    @PostMapping("/update/password")
    public void updatePassword(@RequestBody @Validated UpdatePasswordDTO dto) {
        tblUserService.updatePassword(dto);
    }

    @Operation(summary = "重置密码", description = "重置密码")
    @PostMapping("/rest/password")
    public void restPassword(@RequestBody @Validated UserIdDTO dto) {
        tblUserService.restPassword(dto);
    }

    @Operation(summary = "新增用户", description = "新增用户")
    @PostMapping("/add")
    public void addUser(@RequestBody @Validated UserAddDTO dto) {
        tblUserService.addUser(dto);
    }

    @Operation(summary = "更新用户", description = "更新用户")
    @PostMapping("/update")
    public void updateUser(@RequestBody @Validated UserUpdateDTO dto) {
        tblUserService.updateUser(dto);
    }

    @Operation(summary = "删除用户", description = "删除用户")
    @PostMapping("/delete")
    public void deleteUser(@RequestBody @Validated UserIdDTO dto) {
        tblUserService.deleteUser(dto);
    }

    @Operation(summary = "获取用户基本信息列表", description = "获取用户基本信息列表")
    @PostMapping("/basic/list")
    public List<BasicUserInfo> listBasicUserInfos(@RequestBody UserBasicQueryDTO dto) {
        return tblUserService.listBasicUserInfos(dto);
    }
}
